from base import redis
from base import logger
from base import error_code
from base import misc

# 账号登录
def login(user_name, password):
    red = redis.getRedis()
    if not red:
        return error_code.REDIS_ERROR
    user_key = f'user:{user_name}'
    user_info = red.hgetall(user_key)
    if len(user_info) == 0:
        user_info['uid'] = misc.gen_guid()
        user_info['username'] = user_name
        user_info['password'] = password
    elif password != user_info["password"]:
        logger.info(f"password error user_name={user_name}, password={password}, user_info={user_info}")
        return error_code.PASSWORD_ERROR
    
    return error_code.OK, user_info


# 获取角色列表
def get_char_list(account_id):
    return [
        {
            "charid" : 123,       # 角色id
            "charname" : "test",  # 角色名字
            "charlevel" : 10,     # 角色等级
        },
    ]

    